var wh = require('../../utils/wh.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    forminfo:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.get_setting();
  },
  /**
   * 获取小程序设置
   */
  get_setting: function () {
    let that = this;
    wh.Post('/api/setting/get', {}, function (res) {
      that.setData({ setting: res });
    })
  },
  /**
   * 拨打电话
   */
  call: function () {
    let that = this;
    let setting = that.data.setting;
    let tell = setting.consult_mobile;
    if (tell == '' || tell == undefined) {
      wx.showModal({
        title: '提示', content: '哎呀，还未设置电话号码呢，请稍后再试', showCancel: false
      })
    }
    wx.makePhoneCall({ phoneNumber: tell })
  },
   /**
   * 提交留言信息
   */
  formSubmit: function (e) {

    let that = this;
    let name = e.detail.value.name;
    let mobile = e.detail.value.mobile;
    let content = e.detail.value.content;
    let formid = e.detail.formId;
    if (name == '') {
      wx.showToast({ title: '请填写您的真实姓名', icon: 'none' });
      return;
    }
    if (mobile == '') {
      wx.showToast({ title: '请输入您的手机号', icon: 'none' });
      return;
    }
    if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(mobile))) {
      wx.showToast({ title: '请填写有效的手机号', icon: 'none' });
      return;
    }
    if (content == '') {
      wx.showToast({ title: '请填写您从事的行业', icon: 'none' });
      return;
    }
    wh.Post('/api/common.form/consult', { name: name, mobile: mobile, content: content, formid: formid }, function (res) {
      wx.showToast({ title: '信息提交成功', icon: 'none' });
      that.setData({ forminfo: '' });
    })
  },
/**
 *下拉刷新
 */
  onPullDownRefresh: function () {
    let that = this;
    this.get_setting();
    wx.stopPullDownRefresh();

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})